package com.msk.sys.utils;



import com.aspose.words.*;

import java.io.File;
import java.io.FileOutputStream;
import java.util.UUID;


/**
 * 功能：aspose for java
 * 作者：Zhang_XinGang
 * 时间：2020/2/7 15:13
 */
public class AsposeUtils {

    /**
     * word 转 pdf
     * @param wordPath
     * @return
     */
    public static String wordToPdf(String wordPath,String mkdir){
        String pdfPath = null;
        try {
            AsposeClient asposeClient = new AsposeClient();
            asposeClient.setWordLicense();
            pdfPath = mkdir + "/" + UUID.randomUUID().toString() + ".pdf" ;
            File file = new File(pdfPath);
            FileOutputStream os = new FileOutputStream(file);
            Document doc = new Document(wordPath); // word文档
            // 支持RTF HTML,OpenDocument, PDF,EPUB, XPS转换
            doc.save(os, SaveFormat.PDF);
            os.close();
        }catch (Exception e){
            e.printStackTrace();
        }
        return pdfPath;
    }

    

    /**
     * word添加图片水印
     * @param wordPath
     * @param imgPath
     * @return
     */
    public static String wordInsertWatermark(String wordPath,String imgPath){

        try {
            String randomTemp = UUID.randomUUID().toString().replace("-","");
            AsposeClient asposeClient = new AsposeClient();
            asposeClient.setRandomTemp(randomTemp);

            return asposeClient.wordInsertWatermark(wordPath,imgPath);
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
}
